/*-
 * CMEError.java
 *
 * $LastChangedBy:  $
 * $LastChangedRevision:  $
 * $LastChangedDate:  $
 * $HeadURL: $
 *
 * Copyright (c) 2008, Stein Gunnar Bakkeby
 * All rights reserved.
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of Stein Gunnar Bakkeby nor the names of its
 *       contributors may be used to endorse or promote products derived
 *       from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package com.googlecode.attention;


public enum CMEError {

  /* CME Errors related to GSM 07.07 */
  PHONE_FAILURE(0),
  NO_CONNECTION_TO_PHONE(1),
  PHONE_ADAPTER_LINK_RESERVED(2),
  OPERATION_NOT_ALLOWED(3),
  OPERATION_NOT_SUPPORTED(4),
  PH_SIM_PIN_REQUIRED(5),
  PH_FSIM_PIN_REQUIRED(6),
  PH_FSIM_PUK_REQUIRED(7),
  SIM_NOT_INSERTED(10),
  SIM_PIN_REQUIRED(11),
  SIM_PUK_REQUIRED(12),
  SIM_FAILURE(13),
  SIM_BUSY(14),
  SIM_WRONG(15),
  INCORRECT_PASSWORD(16),
  SIM_PIN2_REQUIRED(17),
  SIM_PUK2_REQUIRED(18),
  MEMORY_FULL(20),
  INVALID_INDEX(21),
  NOT_FOUND(22),
  MEMORY_FAILURE(23),
  TEXT_STRING_TOO_LONG(24),
  INVALID_CHARACTERS_IN_TEXT_STRING(25),
  DIAL_STRING_TOO_LONG(26),
  INVALID_CHARACTERS_IN_DIAL_STRING(27),
  NO_NETWORK_SERVICE(30),
  NETWORK_TIMEOUT(31),
  NETWORK_NOT_ALLOWED__EMERGENCY_CALLS_ONLY(32),
  NETWORK_PERSONALISATION_PIN_REQUIRED(40),
  NETWORK_PERSONALISATION_PUK_REQUIRED(41),
  NETWORK_SUBSET_PERSONALISATION_PIN_REQUIRED(42),
  NETWORK_SUBSET_PERSONALISATION_PUK_REQUIRED(43),
  SERVICE_PROVIDER_PERSONALISATION_PIN_REQUIRED(44),
  SERVICE_PROVIDER_PERSONALISATION_PUK_REQUIRED(45),
  CORPORATE_PERSONALISATION_PIN_REQUIRED(46),
  CORPORATE_PERSONALISATION_PUK_REQUIRED(47),
  MASTER_PHONE_CODE_REQUIRED(48),
  UNKNOWN(100),
  OPERATION_TEMPORARY_NOT_ALLOWED(256),
  CALL_BARRED(257),
  PHONE_IS_BUSY(258),
  USER_ABORT(259),
  INVALID_DIAL_STRING(260),
  SS_NOT_EXECUTED(261),
  SIM_BLOCKED(262),
  
  /* GPRS-related CME Errors */
  ILLEGAL_MS(103),
  ILLEGAL_ME(106),
  GPRS_SERVICES_NOT_ALLOWED(107),
  PLMN_NOT_ALLOWED(111),
  LOCATION_AREA_NOT_ALLOWED(112),
  ROAMING_NOT_ALLOWED_IN_THIS_AREA(113),
  SERVICE_OPTION_NOT_SUPPORTED(132),
  REQUESTED_SERVICE_OPTION_NOT_SUBSCRIBED(133),
  SERVICE_OPTION_TEMPORARILY_OUT_OF_ORDER(134),
  UNSPECIFIED_GPRS_ERROR(148),
  PDP_AUTHENTICATION_FAILURE(149),
  INVALID_MOBILE_CLASS(150),
  
  /* CME Errors related to GSM 07.05 */
  
  UNASSIGNED_NUMBER(1), // (unallocated)
  OPERATOR_DETERMINED_BARRING(8),
  CALL_BARRED_10(10),
  SHORT_MESSAGE_TRANSFER_REJECTED(21),
  DESTINATION_OUT_OF_SERVICE(27),
  UNIDENTIFIED_SUBSCRIBER(28),
  FACILITY_REJECTED(29),
  UNKNOWN_SUBSCRIBER(30),
  NETWORK_OUT_OF_ORDER(38),
  TEMPORARY_FAILURE(41),
  CONGESTION(42),
  RESOURCES_UNAVAILABLE_UNSPECIFIED(47),
  REQUESTED_FACILITY_NOT_SUBSCRIBED(50),
  REQUIESTED_FACILITY_NOT_IMPLEMENTED(69),
  INVALID_SHORT_MESSAGE_TRANSFER_REFERENCE_VALUE(81),
  INVALID_MESSAGE_UNSPECIFIED(95),
  INVALID_MANDATORY_INFORMATION(96),
  MESSAGE_TYPE_NON_EXISTENT_OR_NOT_IMPLEMENTED(97),
  MESSAGE_NOT_COMPATIBLE_WITH_SHORT_MESSAGE_PROTOCOL_STATE(98),
  INFORMATION_ELEMENT_NON_EXISTENT_OR_NOT_IMPLEMENTED(99),
  PROTOCOL_ERROR_UNSPECIFIED(111),
  INTERWORKING_UNSPECIFIED(127),
  TELEMATIC_INTERWORKING_NOT_SUPPORTED(128),
  SHORT_MESSAGE_TYPE_0_NOT_SUPPORTED(129),
  CANNOT_REPLACE_SHORT_MESSAGE(130),
  UNSPECIFIED_TP_PID_ERROR(143),
  DATA_CODING_SCHEME_NOT_SUPPORTED(144), // (alphabet)
  MESSAGE_CLASS_NOT_SUPPORTED(145),
  UNSPECIFIED_TP_DCS_ERROR(159),
  COMMAND_CANNOT_BE_ACTIONED(160),
  COMMAND_UNSUPPORTED(161),
  UNSPECIFIED_TP_COMMAND_ERROR(175),
  TPDU_NOT_SUPPORTED(176),
  SC_BUSY(192),
  NO_SC_SUBSCRIPTION(193),
  SC_SYSTEM_FAILURE(194),
  INVALID_SME_ADDRESS(195),
  DESTINATION_SME_BARRED(196),
  SM_REJECTED_DUPLICATE_SM(197),
  TP_VPF_NOT_SUPPORTED(198),
  TP_VP_NOT_SUPPORTED(199),
  D0_SIM_SMS_STORAGE_FULL(208),
  NO_SMS_STORAGE_CAPABILITY_IN_SIM(209),
  ERROR_IN_MS(210),
  MEMORY_CAPABILITY_EXCEEDED(211),
  SIM_APPLICATION_TOOLKIT_BUSY(212),
  SIM_DATA_DOWNLOAD_ERROR(213),
  UNSPECIFIED_ERROR_CAUSE(255),
  ME_FAILURE(300),
  SMS_SERVICE_OF_ME_RESERVED(301),
  OPERATION_NOT_ALLOWED_302(302),
  OPERATION_NOT_SUPPORTED_303(303),
  INVALID_PDU_MODE_PARAMETER(304),
  INVALID_TEXT_MODE_PARAMETER(305),
  SIM_NOT_INSERTED_310(310),
  SIM_PIN_REQUIRED_311(311),
  PH_SIM_PIN_REQUIRED_312(312),
  SIM_FAILURE_313(313),
  SIM_BUSY_314(314),
  SIM_WRONG_315(315),
  SIM_PUK_REQUIRED_316(316),
  SIM_PIN2_REQUIRED_317(317),
  SIM_PUK2_REQUIRED_318(318),
  MEMORY_FAILURE_320(320),
  INVALID_MEMORY_INDEX(321),
  MEMORY_FULL_322(322),
  SMSC_ADDRESS_UNKNOWN(330),
  NO_NETWORK_SERVICE_331(331),
  NETWORK_TIMEOUT_332(332),
  NO_CNMA_ACK_EXPECTED(340),
  UNKNOWN_ERROR(500),
  USER_ABORT_512(512),
  ERROR(-1);
  
  
  private int value;
  
  private CMEError(final int value) {
    this.value = value;
  }
  
  public static CMEError parse(final String value) {
    try {
      return parse(Integer.parseInt(value));
    } catch (NumberFormatException e) {
      throw new IllegalArgumentException(e);
    }
  }
  
  public static CMEError parse(final int value) {
    for (CMEError code : CMEError.values()) {
      if (code.value == value) {
        return code;
      }
    }
    throw new IllegalArgumentException(String.valueOf(value));
  }
}
